<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">

				<el-form-item label="供货商" prop="useruuid">
					<el-select v-model="filters.useruuid" filterable collapse-tags placeholder="请选择供货商"   >
						<el-option value="0" label="全部">全部</el-option>
						<el-option
								v-for="item in users"
								:key="item.user.useruuid"
								:label="item.user.username"
								:value="item.user.useruuid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="业务类型" prop="busuuid">
					<el-select v-model="filters.busuuid" filterable collapse-tags placeholder="请选择业务类型">
						<el-option value="0" label="全部">全部</el-option>
						<el-option
								v-for="item in bus"
								:key="item.busuuid"
								:label="item.busname"
								:value="item.busuuid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="省份" prop="provinceuuid">
					<el-select v-model="filters.provinceuuid" filterable collapse-tags placeholder="请选择省份">
						<el-option value="0" label="全部">全部</el-option>
						<el-option
								v-for="item in info"
								:key="item.provinceuuid"
								:label="item.provincename"
								:value="item.provinceuuid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-input v-model="filters.name" placeholder="面值"></el-input>
				</el-form-item>
				<el-form-item>
					<el-date-picker type="date" placeholder="开始时间" format="yyyy-MM-dd"   v-model="filters.starttime" style="width: 100%;"></el-date-picker>
				</el-form-item>
				<el-form-item>
					<el-date-picker type="date" placeholder="结束时间" format="yyyy-MM-dd"   v-model="filters.endtime" style="width: 100%;"></el-date-picker>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="getup">查询</el-button>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="exportDataUp">导出</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="ups" highlight-current-row v-loading="listLoading" border max-height="620"  @selection-change="selsChange" style="width: 100%;">
			<el-table-column type="index" width="80" label="编号">
			</el-table-column>
			<el-table-column prop="username" label="渠道名称" show-overflow-tooltip  sortable>
			</el-table-column>
			<el-table-column prop="busname" label="业务类型"  sortable>
			</el-table-column>
			<el-table-column prop="operatorname" label="运营商"  sortable>
			</el-table-column>
			<el-table-column prop="provincename" label="省份"  sortable>
			</el-table-column>
			<el-table-column prop="sumamount" label="总订单金额" show-overflow-tooltip sortable>
			</el-table-column>
			<el-table-column prop="success" label="成功金额" show-overflow-tooltip sortable>
			</el-table-column>
			<el-table-column prop="failt" label="失败金额"  sortable>
			</el-table-column>
			<el-table-column prop="wait" label="等待充值金额"  sortable>
			</el-table-column>
			<el-table-column prop="sumorder" label="交易笔数"  sortable>
			</el-table-column>
			<el-table-column prop="successorder" label="成功笔数"  sortable>
			</el-table-column>
			<el-table-column prop="failtorder" label="失败笔数"  sortable>
			</el-table-column>
			<el-table-column prop="successRate" label="成功率"  sortable>
			</el-table-column>
			<el-table-column prop="waitorder" label="等待订单数量"  sortable>
			</el-table-column>
			<el-table-column prop="profit" label="利润"  sortable>
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-pagination
				@current-change="handleCurrentChangeMatch"
				@size-change="handleSizeChangeMatch"
				layout="total,sizes,prev, pager, next"
				:total="total">
		</el-pagination>

	</section>
</template>

<script>
	import util from '../../common/js/util'
	//import NProgress from 'nprogress'
	import { findAllUpShopInfo ,findOpeProBusShop,getUpCount,exportDataUp } from '../../api/api';
    import moment from 'moment';
	export default {
		data() {
			return {
                filters: {
                    useruuid: '',
                    busuuid:'',
                    provinceuuid:'',
                    facevalue:'',
                    starttime:new Date(),
                    endtime:new Date()
                },
                users: [],
                bus:[],
                info:[],
                ups:[],
                total: 0,
                start: 0,
                pageSize: 10,
                listLoading: false
			}
		},
		methods: {
			//性别显示转换
			formatSex: function (row, column) {
				return row.sex == 1 ? '男' : row.sex == 0 ? '女' : '未知';
			},
            handleCurrentChangeMatch: function (val) {
                this.start = val ;
                this.getup();
            },
            handleSizeChangeMatch: function (val) {
                this.pageSize = val;
                this.getup();
            },
            getup() {
				let para = {
                    start: this.start,
                    pageSize: this.pageSize,
                    useruuid: this.filters.useruuid,
                    busuuid: this.filters.busuuid,
                    provinceuuid:this.filters.provinceuuid,
                    facevalue:this.filters.facevalue,
                    starttime:this.filters.starttime == "" ? "" : moment(this.filters.starttime,"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD'),
                    endtime:this.filters.endtime == "" ? "" : moment(this.filters.endtime,"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD')
				};
                this.listLoading = true;
                getUpCount(para).then(datas =>{
                    this.listLoading = false;
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        if (code === "37") {
                            this.$router.push({path: '/login'});
                        }
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.total = datas.data.totalCount;
                        this.ups = datas.data.result;
                    }
				}).catch(e =>{
                    this.listLoading = false;
				});

			},
            exportDataUp:function () {
                let para = {
                    useruuid: this.filters.useruuid,
                    busuuid: this.filters.busuuid,
                    provinceuuid:this.filters.provinceuuid,
                    facevalue:this.filters.facevalue,
                    starttime:this.filters.starttime == "" ? "" : moment(this.filters.starttime,"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD'),
                    endtime:this.filters.endtime == "" ? "" : moment(this.filters.endtime,"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD')
                };
                exportDataUp(para).then(res =>{
                    let {message, code, data} = res;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        window.open(data.path);
                    }
				});

            },
			selsChange: function (sels) {
				this.sels = sels;
			},handleAdd:function () {

            },findAllUpShopInfo:function () {
                let para = {
                    page: this.page,
                };
                findAllUpShopInfo(para).then(datas => {
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        if (code === "37") {
                            this.$router.push({path: '/login'});
                        }
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.users = data;
                    }
                }).catch(e =>{
                    this.listLoading = false;
                });;
            },
            findOpeProBusShop:function(){
                let para = {
                    test: ''
                };
                findOpeProBusShop(para).then(datas => {
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.operator = data.operator;
                        this.info = data.info;
                        this.bus = data.bus;
                    }
                }).catch(e =>{
                    this.listLoading = false;
                });
            }
			},
		mounted() {
//		    this.getup()
			this.findAllUpShopInfo();
		    this.findOpeProBusShop();
		}
	}

</script>

<style scoped>

</style>
